﻿using Emgu.CV.CvEnum;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace OpenCvApplication.View.CommonView
{
    public partial class MedianBlurParameterControl : UserControl
    {
        public MedianBlurParameterControl()
        {
            InitializeComponent();

            foreach (Control item in this.Controls)
            {
                if (item is TrackBar trackBar)
                    trackBar.Scroll += trackBar_Scroll;
            }
        }
        private void trackBar_Scroll(object sender, EventArgs e)
        {
            TrackBar trackBar = (TrackBar)sender;
            if ((trackBar.Value & 1) == 0)
            {
                trackBar.Value++;
            }
            RefreshShow();
            ValueChange?.Invoke(this, Args);
        }
        public Action<object, MedianBlurEventArgs> ValueChange { get; set; }
        private void MedianBlurParameterControl_Load(object sender, EventArgs e)
        {
            ValueChange?.Invoke(this, Args);
        }
        private void RefreshShow()
        {
            lblSizeWidth.Text = KSize.ToString();
        }
        public int KSize
        {
            get => tcbSizeWidth.Value;
        }
        public MedianBlurEventArgs Args
        {
            get=> new MedianBlurEventArgs(KSize);
        }
    }
    public class MedianBlurEventArgs : EventArgs
    {
        public MedianBlurEventArgs()
        {
            
        }
        public MedianBlurEventArgs(int kSize) : this()
        {
            this.KSize = kSize;
        }
        public int KSize { get; set; }
    }
}
